package com.j283_5.wisdom_park.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.j283_5.wisdom_park.common.result.ResultData;
import com.j283_5.wisdom_park.mapper.OpelogmanageMapper;
import com.j283_5.wisdom_park.mapper.OrgmanageMapper;
import com.j283_5.wisdom_park.pojo.Orgmanage;
import com.j283_5.wisdom_park.pojo.Roleinfo;
import com.j283_5.wisdom_park.service.OrgmanageService;
import com.j283_5.wisdom_park.vo.confcenter_management.OrgManageVo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author laoda
 * @since 2022-04-28
 */
@Service
public class OrgmanageServiceImpl extends ServiceImpl<OrgmanageMapper, Orgmanage> implements OrgmanageService {
    @Resource
    private OrgmanageMapper orgmanageMapper;

    @Override
    public ResultData getOrgManage(Page<Orgmanage> page, Orgmanage orgmanage) {
        if (page==null){
            page=new Page<>(1,10);
        }
        QueryWrapper<Orgmanage> orgmanageQueryWrapper=new QueryWrapper<>();
        orgmanageQueryWrapper.eq("or_state",0);
        orgmanageQueryWrapper.orderByAsc("or_num");
        if (orgmanage.getOrName()!=null){
            orgmanageQueryWrapper.like("or_name",orgmanage.getOrName());
        }
        if (orgmanage.getOrType()!=null){
            orgmanageQueryWrapper.eq("or_type",orgmanage.getOrType());
        }
        Page<Orgmanage> orgmanagePage=orgmanageMapper.selectPage(page,orgmanageQueryWrapper);
        if (orgmanagePage!=null){
            return ResultData.ok().data(orgmanagePage);
        }else {
            return ResultData.ok().data("查询失败!");
        }
    }

    @Override
    public ResultData addOrgManage(OrgManageVo orgManageVo) {
        Orgmanage orgmanage=new Orgmanage();
        BeanUtils.copyProperties(orgManageVo,orgmanage);
        int i=orgmanageMapper.insert(orgmanage);
        if (i>0){
            return ResultData.ok().data("添加成功!");
        }else {
            return ResultData.ok().data("添加失败!");
        }
    }

    @Override
    public ResultData deleteOrgManage(ArrayList<Integer> orIdlist) {
        UpdateWrapper<Orgmanage> orgmanageUpdateWrapper=new UpdateWrapper<>();
        orgmanageUpdateWrapper.set("or_state",1);
        orgmanageUpdateWrapper.in("or_id",orIdlist);
        int i=orgmanageMapper.update(null,orgmanageUpdateWrapper);
        if (i>0){
            return ResultData.ok().data("删除成功!");
        }else {
            return ResultData.ok().data("删除失败!");
        }
    }

    @Override
    public ResultData updateorgmanage(Orgmanage orgmanage) {
        UpdateWrapper<Orgmanage> orgmanageUpdateWrapper=new UpdateWrapper<>();
        orgmanageUpdateWrapper.eq("or_id",orgmanage.getOrId())
                .set("or_name",orgmanage.getOrName())
                .set("or_type",orgmanage.getOrType())
                .set("or_num",orgmanage.getOrNum())
                .set("or_updatetime",orgmanage.getOrUpdatetime());
        int i=orgmanageMapper.update(null,orgmanageUpdateWrapper);
        if (i>0){
            return ResultData.ok().data("修改成功!");
        }else {
            return ResultData.ok().data("修改失败!");
        }
    }
}
